<?php
namespace App\Admin\Controllers;


use App\Http\Controllers\Controller;
use App\Models\OrderForm;
use Encore\Admin\Facades\Admin;
use Encore\Admin\Layout\Column;
use Encore\Admin\Layout\Content;
use Encore\Admin\Layout\Row;
use Encore\Admin\Grid;

use Encore\Admin\Form;

use Illuminate\Http\Request;
use \Illuminate\Support\Facades\Input;
use App\Models\Account\PlayerActModel;
use App\Models\Area;

use App\Admin\Extra\Search\Html;

class OrderFormController extends Controller
{
    public function anyListAccount()
    {
        $req_param = Input::all();
        //OrderForm::getAccountByName();
        return Admin::content(function (Content $content)use($req_param) {

            $content->header('order form');
            $content->description('server baseic config. this is very important,it is related that is the game server running normally, Please dont change at will. Please contact the area manager if you want to change an area info ');

            $content->row(Html::append([
                Html::input('cp_player_id', 'cp_player_id', url()->current()),
                Html::button('GO', url()->current(), 'search-filter'),
                Html::sjs(url()->current())
            ]));


            $grid = Admin::grid(OrderForm::class, function(Grid $grid){

//                $grid->model()->where('deleted_at', 0);
                $grid->actions(function($actions){
                    $actions->disableDelete();
                    $actions->disableEdit();
                    $actions->append('<a href="'.url('admin/orderform/show?_id='). $actions->row->id .'"><i class="glyphicon glyphicon-eye-open"></i></a>');
                    });

                // 第一列显示id字段，并将这一列设置为可排序列
                $grid->id('id');
                $grid->model()->orderBy('id', 'DESC');

                // 第二列显示title字段，由于title字段名和Grid对象的title方法冲突，所以用Grid的column()方法代替
                $grid->column('mc');
//                $grid->mainChannel('main channel');
                $grid->column('OrderSerial');
                $grid->column('CooperatorOrderSerial');
                $grid->column('UID');
                $grid->column('MerchandiseName');
                $grid->column('OrderMoney');
                $grid->column('StartDateTime');
                $grid->column('BankDateTime');
                $grid->column('OrderStatus');
                $grid->column('StatusMsg');
                $grid->column('VoucherMoney');
                $grid->column('cp_goods_title');
//                $grid->columns('cp_extra');
                $grid->column('cp_area');
                $grid->column('cp_product_id');
                $grid->column('cp_curr_server');
                $grid->column('cp_account');
                $grid->column('cp_player_id');
                $grid->column('cp_diamond');
                $grid->column('cp_rmb');
                $grid->column('deleted_at');
                $grid->column('updated_at');
                $grid->column('created_at');
                $grid->column('timestamp');
                $grid->column('created_time');


                // 禁用按钮
//                $grid->disableCreateButton();

                // filter($callback)方法用来设置表格的简单搜索框
//                $grid->filter(function ($filter)use($area_data) {
//
//                    // 模糊查询 注意
//                    $filter->where(function($query){
//                        $aids = \App\Models\Account\PlayerActModel::getAccountByName('', 'playerName');
//                        //var_dump($aids);exit;
//                        $query->whereIn('account', $aids?:[]);
//                    }, 'player name', 'playerName');
//
//                    $filter->equal('account', 'account')->placeholder('user account');
//                    $filter->equal('lastPlayerId', 'player id')->placeholder('player id');
//
//                    $filter->in('mainChannel', 'main channel')->multipleSelect(Area::$area_mc);
//                    $filter->equal('lastAreaId', 'area chioce')->select($area_data);
//
//                    // 设置created_at字段的范围查询
//                    $filter->between('created_at', 'Created Time')->datetime();
//
//                    //
//                    $filter->disableIdFilter();
//                });

                $grid->filter(function ($filter){

                    // 模糊查询 注意
                    //$filter->where(function($query){
                    //    //$aids = \App\Models\EMail::getAccountByName('', 'playerName');
                    //    //var_dump($aids);exit;
                    //    $query->where('title', 'like', 'T%');
                    //}, '邮件标题', 'title');

                    $filter->like('cp_player_id', 'cp_player_id')->placeholder('');
                    //$filter->disableIdFilter();
                });
//                $grid->disableCreateButton();
//                //$grid->disableExport();
//                $grid->disableActions();
//                $grid->disableRowSelector();
            });
            $content->row($grid->render());
            //$content->body(phpinfo());
        });


    }

    public function anyShow(Request $request) {
        $accountId = $request->get('_id');
        $info = OrderForm::detailPlayer($accountId);
        $data = [
            'title_act' => 'account operator',
        ];
        $data = array_merge($data, $info);
        return Admin::content(function (Content $content) use($data){
            $content->header('订单详情');
            $content->description('.....');

            $content->row(view('admin.orderform.orderform_show', $data?:[]));

        });
    }
//    删除订单
//    public function anyApiSave(Request $request){
//        $data = Input::all();
//        $id = $request->get('_id');
//
//        //实例化OrderForm
//        $model = new OrderForm();
//        $model::del($id);
//        //返回主页面QAQ
//        return $this->anyListAccount();
//    }


//    修改订单
//    public function anyEdit(){
//        $id = Input::get('id');
//
//        $one = OrderForm::find($id) ?: new OrderForm();
//
//        $data['one'] = $one;
//        \Log::debug("notice notice",[Area::areaSelectData(), intval($one->area_list)]);
//        return Admin::content(function($content) use($data){
//            $content->header('订单');
//            $grid = Admin::Form(OrderForm::class, function(Form $form)use($data){
//                $one = $data['one'];
//
//                $form->text('area', 'area')->default($one->area);
//                $form->text('udid', 'udid')->default($one->udid);
//                $form->text('accout id', 'accout id')->default($one->account_id);
//                $form->text('player id', 'player id')->default($one->player_id);
//                $form->text('level', 'level')->default($one->level);
//                $form->hidden('_id', 'id')->default($one->id);
//                $form->setAction('orderform/api-save');
//            });
//            $content->row($grid);
//        });
//
//    }

}
